<?php
//
?>
<!doctype html>
<html lang="fr">
    <head>
        <meta charset="utf-8">
        <title>Server Sent Event SSE</title>
        <script type="text/javascript" src="js/jquery.min.js"></script>
    </head>
    <body>
        <div id="sse-result">
            <!-- -->
        </div>
        <script type="text/javascript">
            //$(function() {
                if (typeof (EventSource) != 'undefined') {
                    var source = new EventSource("sse.php");
                    source.onmessage = function(e) {                        
                        //document.getElementById('sse-result').innerHTML += 'Date : ' + data.date + '<br>Heure : ' + data.heure + '<br>';
                        data = JSON.parse(e.data);
                        document.getElementById("sse-result").innerHTML += data.date + "<br>";
                    };
                } else {
                    // Ne supporte pas le SSE
                    alert("Votre navigateur ne supporte pas le SSE");
                }
            //});
        </script>
    </body>
</html>